﻿using System;
using System.IO;
using Framework.Unity.Extensions;
using Microsoft.Practices.Unity;
using NUnit.Framework;

namespace WebCrawler.Tests.Integration
{
    public class TestLogger : UrlLogger
    {
        public TestLogger(IFileManager fileManager) : base(fileManager)
        {
        }
    }
    public class UrlLoggerTests : IntegrationTestFixture
    {
        private IUrlLogger _logger;

        [SetUp]
        public new void Setup()
        {
            RootContainer.RegisterType<IUrlLogger, TestLogger>();
        }

        [Test] public void ShouldResolve()
        {
            _logger = RootContainer.Resolve<IUrlLogger>();
            Assert.NotNull(_logger);
        }

        [Test] public void ShouldCreateFiles()
        {
            var tempDir = "logdir_" + Guid.NewGuid();
            _logger = RootContainer.InstanceOf<UrlLogger>()
                .WithProperty(z => z.FileSize, 10)
                .WithProperty(z => z.LogDirectory, tempDir)
                .Resolve();
            _logger.Start();
            _logger.WriteLine("12345");
            _logger.WriteLine("12345");
            _logger.WriteLine("123456");
            _logger.Stop();

            string directory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, tempDir);
            ExpectFilesInDirectory(directory, 2);
            Directory.Delete(directory, true);
        }
    }
}